package com.example.timeplanning_teacher;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import org.jetbrains.annotations.Nullable;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

public class FragmentParents extends Fragment {


    private TextView tx_parent_name;
    private TextView tx_username;
    private TextView tx_student_name;
    private SharedPreferences sp;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {


        return inflater.inflate(R.layout.fragment_parents, container, false);
    }

    public void onStart(){
        super.onStart();
        sp = getActivity().getSharedPreferences("parent", Context.MODE_PRIVATE);
        tx_parent_name = getView().findViewById(R.id.tx_parent_name);
        tx_username = getView().findViewById(R.id.tx_username);
        tx_student_name = getView().findViewById(R.id.tx_student_name);
        tx_parent_name.setText(sp.getString("parent_name",""));
        tx_username.setText(getStarMobile(sp.getString("username","")));
        tx_student_name.setText(getStarMobile(sp.getString("student_username","")));

    }
    public String getStarMobile(String mobile) {
        if (!TextUtils.isEmpty(mobile)) {
            if (mobile.length() >=11)

                return mobile.substring(0,3) +"****" + mobile.substring(7, mobile.length());

        }else {
            return "";

        }

        return mobile;

    }

    public static FragmentParents newInstance() {
        return new FragmentParents();
    }
}
